﻿using M_Bom.API.Application.Command.BomCommand;
using M_Bom_Domain;
using M_Bom_Repository.Interface;
using MediatR;

namespace M_Bom.API.Application.CommandHandler.BomCommandHandler
{
    public class BomBackfillBomCommandHandler : IRequestHandler<BomBackfillBomCommand, Bom>
    {
        protected readonly IBom bom;

        public BomBackfillBomCommandHandler(IBom bom)
        {
            this.bom = bom;
        }

        public async Task<Bom> Handle(BomBackfillBomCommand request, CancellationToken cancellationToken)
        {
            var res = await bom.GetAsync(o => o.Bombh == request.Bombh);
            var boms = await bom.GetModelAsync(res.FirstOrDefault().Bomid);
            return boms;
        }
    }
}
